import Vue from "vue";
import VueRouter from "vue-router";

import Login from "@/views/Login";
// 路由懒加载
const Search = () => import(/* webpackChunkName: "Search" */ "@/views/Search");
const Detail = () => import(/* webpackChunkName: "Detail" */ "@/views/Detail");

Vue.use(VueRouter);

import Register from '@/views/Register'
import Edit from '@/views/Edit'
import Vip from '@/views/vip'
import Index from '@/views/myZhenai'
import Personal from '@/views/Personal'
import Map from '@/views/Map'
import Follow from '@/views/messageCenter/Follow'
import Message from '@/views/messageCenter/Message'
Vue.use(VueRouter)
const routes = [
  {
    path: "/login",
    name: "Login",
    component: Login,
   
  },
  {
    path: "/",
    name: "Register",
    component: Register,
  },
  {
    path: "/edit",
    name: "Edit",
    component: Edit,
  },
  {
    path: "/vip",
    name: "Vip",
    component: Vip,
    meta:3
  },
  {
    path: "/search",
    name: "Search",
    component: Search,
    meta:2
  },
  {
    path: "/detail",
    name: "Detail",
    component: Detail,
    
  },
  {
    path: "/index",
    name: "Index",
    component: Index,
    meta:1
  },
  {
    path: "/personal",
    name: "Personal",
    component: Personal,
  },
  {
    path: "/map",
    name: "Map",
    component: Map,
  },
  {
    path: "/follow",
    name: "Follow",
    component: Follow,
  },
  {
    path: "/message",
    name: "Message",
    component: Message,
  }
];
const router = new VueRouter({
  mode: 'history',
  routes
})
const routerList = ['Detail','Index','Personal','Search','Vip','Map']
router.beforeEach((to, from, next) => {
  
  const token = JSON.parse(window.localStorage.getItem('cookie'))
  if(routerList.indexOf(to.name) === -1 ||token){
    console.log(111);
    next()
    return
  }
    next(`/?redirect=${to.path}`)
  
})
export default router;
